package com.usefullc.english.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.common.enums.ValidActionEnum;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.english.domain.UserWordDict;
import com.usefullc.english.param.UserWordDictParam;
import com.usefullc.english.vo.UserWordDictVo;
import com.usefullc.english.query.UserWordDictQuery;
import com.usefullc.english.service.UserWordDictService;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.system.controller.BaseController;
import com.usefullc.system.controller.WebResultBuilder;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.param.IdsParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.validation.Valid;

import static com.usefullc.system.controller.WebResultBuilder.successResult;

/**
 * 用户词典控制类
 * @author: 星空
 * @date: 2022-08-11
 */
@RestController
@RequestMapping("/english/userWordDict/")
@Api( tags="用户词典")
public class UserWordDictController extends BaseController {

    @Autowired
    private UserWordDictService userWordDictService;

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "用户词典列表",response = WebResult.class)
    @GetMapping(path = "list",produces = "application/json")
    public WebResult list(@UsefulValid(query = true) UserWordDictQuery query) {
        Pager<UserWordDictVo> page = userWordDictService.findVoByPage(query);
        return WebResultBuilder.successResult(page);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "用户词典所有列表", response = WebResult.class)
    @GetMapping(path = "listAll", produces = "application/json")
    public WebResult listAll(@UsefulValid(query = true) UserWordDictQuery query) {
        List<UserWordDict> dataList = userWordDictService.findAll(query);
        return WebResultBuilder.successResult(dataList);
    }


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "用户词典详情",response = WebResult.class)
    @GetMapping(path = "detail",produces = "application/json")
    public WebResult detail(@ApiParam(value = "示例ID") @Valid @RequestParam Long id) {
        UserWordDict userWordDict = userWordDictService.findById(id);
        return WebResultBuilder.successResult(userWordDict);
    }


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "创建用户词典", response = WebResult.class)
    @PostMapping(path = "/save", produces = "application/json")
    @UsefulValid
    public WebResult save(@UsefulValid(save=true) @RequestBody UserWordDictParam param) {
        UserWordDict userWordDict = BeanUtils.beanCopy(param, UserWordDict.class);
        return successResult(userWordDictService.save(userWordDict));
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "修改用户词典", response = WebResult.class)
    @PostMapping(path = "/update", produces = "application/json")
    public WebResult update(@UsefulValid(update=true) @RequestBody UserWordDictParam param) {
        UserWordDict oldBean = userWordDictService.findById(param.getId());
        BeanUtils.beanCopy(param, oldBean);
        return successResult(userWordDictService.update(oldBean));
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "del",produces = "application/json")
    @ApiOperation(value = "删除用户词典",response = WebResult.class)
    public WebResult del(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        userWordDictService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "delByLogic",produces = "application/json")
    @ApiOperation(value = "逻辑删除用户词典",response = WebResult.class)
    public WebResult delByLogic(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        userWordDictService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }






}
